Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send v1 to v1 receivers if v2 unsupported #335

Merged
merged 4 commits into from
Aug 9, 2024

Conversation

DanGould
Copy link
Contributor

@DanGould DanGould commented Jul 30, 2024

Fix #144

This lets v2 feature enabled senders attempt a v1 send if v2 request session public keys are not available.

It does this entirely within the send state machine and requires minimal changes upstream (just setting the content-type header from Request instead of manually.

  • Patch 1 changes a pure function to a method since it's only ever used as a method
  • Patch 2 includes the content-type header in the Request struct, since the extract_v2 method will switch depending on what it returns, and it makes it more obvious what header to set for all requests
  • Patch 3 actually fixes the bug and has extract_v2 return the fallback if no v2 pubkey is available
  • Patch 4 removes a duplicate print statement

It uncovered some of the issues with the feature gated error variants in the send module, which probably could be separated. It also uncovered that the integration tests do not use an actual HTTP server for V1 test cases, which I think is OK but I want to raise as a consideration.

  • write an integration test

@DanGould
Copy link
Contributor Author

DanGould commented Aug 3, 2024

I've discovered that this strategy of making a request won't work to make v1 requests from v2 in nearly every case because v2 requests will fail to build because they won't parse a public key from the payjoin endpoint. Therefore, matching should be done on the error type in extraction rather than for a response containing a "version unsupported" error that will never be received.

Rename it from rs_pubkey_from_dir_endpoint.
Return error::ParseSubdirectoryError, that covers all variants.
@DanGould DanGould force-pushed the v2-to-v1 branch 3 times, most recently from 5beb7be to efae797 Compare August 6, 2024 18:39
@DanGould
Copy link
Contributor Author

DanGould commented Aug 6, 2024

I think this is ready for review but I don't totally love the v2 interface exposing pub fn extract_v1 and pub_fn extract_v2 just for testing. It seemed necessary to test that v1 senders (compiled with v2 features) can send to v2 receivers. Otherwise, Some test needs to be written to compile completely separate feature sets, which in time I would like to get rid of, in order to test the backwards compatibility.

trading extract_v1 and extract_v2 for a combined extract_req makes for an understandable interface so I just left them both public. I think it works even if v2 senders may only rarely call extract_v1. extract_v2 depends on it, so it's no more to compile, just to expose.

The subsequent extract_v2 method may fall back to a v1 request
depending on the Url it is given, requiring a different
content-type from a v2 request.
If no V2 subdirectory public key is available, try V1.
@DanGould DanGould marked this pull request as ready for review August 7, 2024 18:56
@DanGould DanGould requested a review from spacebear21 August 7, 2024 18:59
Copy link
Collaborator

@spacebear21 spacebear21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK 3d29412

@DanGould DanGould merged commit 908aa5c into payjoin:master Aug 9, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Send v1 requests to v1 receivers even if v2 feature is enabled
2 participants